# 基础镜像
FROM python:3.10-slim

# 设置时区和中文支持
ENV TZ=Asia/Shanghai
ENV LANG=C.UTF-8



# 默认环境变量（可在docker run时用-e覆盖）
ENV VIDEO_SOURCE_DIR="/app/videos"
ENV PREVIEW_SAVE_DIR="/app/previews"
ENV FAVORITE_DIR="/app/favorites"
ENV DATABASE_PATH="/app/preview.db"
ENV FFMPEG_PATH="ffmpeg"
ENV FFPROBE_PATH="ffprobe"
ENV MIN_VIDEO_DURATION=30
ENV MID_VIDEO_DURATION=300
ENV PREVIEW_WIDTH=320
ENV PREVIEW_HEIGHT=240
ENV PREVIEW_DURATION=3
ENV GIF_FPS=10
ENV GIF_QUALITY=80
ENV PER_PAGE=12


# 替换apt为阿里云bookworm源
RUN echo "deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free\n\
deb https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free\n\
deb https://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free\n\
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free" \
> /etc/apt/sources.list

# 安装依赖
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        ffmpeg \
        libsm6 \
        libxext6 \
        && rm -rf /var/lib/apt/lists/*

# 创建工作目录
WORKDIR /app

# 复制项目文件
COPY . /app

# 安装Python依赖
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

# 暴露端口
EXPOSE 5000

# 支持外部挂载视频目录、预览目录
VOLUME ["/app/videos", "/app/previews"]

# 启动命令
CMD ["python", "app.py"]